// $Id: ITPreferences.m,v 1.61 2003/08/13 05:03:54 sgehrman Exp $
/*
 **  ITPreferences.m
 **
 **  Copyright (c) 2002, 2003
 **
 **  Author: Fabian, Ujwal S. Sathyam
 **
 **  Project: iTerm
 **
 **  Description: Implements the model and controller for the preference panel.
 **
 **  This program is free software; you can redistribute it and/or modify
 **  it under the terms of the GNU General Public License as published by
 **  the Free Software Foundation; either version 2 of the License, or
 **  (at your option) any later version.
 **
 **  This program is distributed in the hope that it will be useful,
 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 **  GNU General Public License for more details.
 **
 **  You should have received a copy of the GNU General Public License
 **  along with this program; if not, write to the Free Software
 **  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#import "ITPreferences.h"
#import "NSString+Communique.h"

static NSString* kScrollbackPrefKey = @"NTTerm_ScrollbackPrefKey";
static NSString* kAntiAliasPrefKey = @"NTTerm_AntiAliasPrefKey";
static NSString* kMacintoshNavKeysPrefKey = @"NTTerm_MacintoshNavKeysPrefKey";
static NSString* kOptionKeyModePrefKey = @"NTTerm_OptionKeyModePrefKey";
static NSString* kHideTabPrefKey = @"NTTerm_HideTabPrefKey";
static NSString* kSilenceBellPrefKey = @"NTTerm_SilenceBellPrefKey";
static NSString* kTabViewTypePrefKey = @"NTTerm_TabViewTypePrefKey";
static NSString* kBlinkCursorPrefKey = @"NTTerm_BlinkCursorPrefKey";
static NSString* kEnforceCharacterAlignmentPrefKey = @"NTTerm_EnforceCharacterAlignmentPrefKey";

@implementation ITPreferences

+ (ITPreferences*)sharedInstance;
{
    static ITPreferences* shared = nil;
    
    if (!shared)
        shared = [[ITPreferences alloc] init];
    
    return shared;
}

- (id)init
{
    self = [super init];
    
    _userDefaults = [NSUserDefaults standardUserDefaults];
    
    return self;
}

- (void)dealloc
{
    [super dealloc];
}

- (unsigned int)numScrollbackLines;
{
    if ([_userDefaults objectForKey:kScrollbackPrefKey])
        return (unsigned) [_userDefaults integerForKey:kScrollbackPrefKey];

    return 100000; // default value
}

- (void)setNumScrollbackLines:(unsigned int)set;
{
    [_userDefaults setInteger:(int)set forKey:kScrollbackPrefKey];
}

- (BOOL)antiAlias;
{
    if ([_userDefaults objectForKey:kAntiAliasPrefKey])
        return [[_userDefaults objectForKey:kAntiAliasPrefKey] boolValue];
    
    return NO; // default value
}

- (void)setAntiAlias:(BOOL)set;
{
    [_userDefaults setBool:set forKey:kAntiAliasPrefKey];
}

- (ITOptionKeyMode)optionKeyMode;
{
    if ([_userDefaults objectForKey:kOptionKeyModePrefKey])
        return (ITOptionKeyMode) [_userDefaults integerForKey:kOptionKeyModePrefKey];
    
    return OPT_NORMAL;
}

- (void)setOptionKeyMode:(ITOptionKeyMode)set;
{
    [_userDefaults setInteger:set forKey:kOptionKeyModePrefKey];
}

- (BOOL)macintoshNavKeys;
{
    if ([_userDefaults objectForKey:kMacintoshNavKeysPrefKey])
        return [[_userDefaults objectForKey:kMacintoshNavKeysPrefKey] boolValue];
    
    return NO;
}

- (void)setMacintoshNavKeys:(BOOL)set;
{
    [_userDefaults setBool:set forKey:kMacintoshNavKeysPrefKey];
}

- (BOOL)hideTab;
{
    if ([_userDefaults objectForKey:kHideTabPrefKey])
        return [[_userDefaults objectForKey:kHideTabPrefKey] boolValue];
    
    return YES;
}

- (void)setHideTab:(BOOL)set;
{    
    [_userDefaults setBool:set forKey:kHideTabPrefKey];
}

- (BOOL)silenceBell;
{
    if ([_userDefaults objectForKey:kSilenceBellPrefKey])
        return [[_userDefaults objectForKey:kSilenceBellPrefKey] boolValue];
    
    return NO;
}

- (void)setSilenceBell:(BOOL)set;
{
    [_userDefaults setBool:set forKey:kSilenceBellPrefKey];
}

- (NSTabViewType)tabViewType;
{
    if ([_userDefaults objectForKey:kTabViewTypePrefKey])
        return (NSTabViewType) [[_userDefaults objectForKey:kTabViewTypePrefKey] intValue];
    
    return NSTopTabsBezelBorder;
}

- (void)setTabViewType:(NSTabViewType)set;
{
    [_userDefaults setInteger:(int)set forKey:kTabViewTypePrefKey];
}

- (BOOL)blinkCursor;
{
    if ([_userDefaults objectForKey:kBlinkCursorPrefKey])
        return [[_userDefaults objectForKey:kBlinkCursorPrefKey] boolValue];
    
    return YES;
}

- (void)setBlinkCursor:(BOOL)set;
{
    [_userDefaults setBool:set forKey:kBlinkCursorPrefKey];
}

- (BOOL)enforceCharacterAlignment;
{
    if ([_userDefaults objectForKey:kEnforceCharacterAlignmentPrefKey])
        return [[_userDefaults objectForKey:kEnforceCharacterAlignmentPrefKey] boolValue];
    
    return NO; // turn off for default - too buggy
}

- (void)setEnforceCharacterAlignment:(BOOL)set;
{
    [_userDefaults setBool:set forKey:kEnforceCharacterAlignmentPrefKey];
}

@end

